package com.whty.common;

import java.io.File;



/**
 * 系统路径对象，用于返回指定的文件或文件夹路径
 * 
 * @author leijun. 2009-10-04
 * */
public class Path {

	private Path(){
	}
	private static Path instance = null;
	/**
	 * 单例模式构造
	 * */
	public static Path getInstance(){
		if(instance == null){
			instance = new Path();
		}
		return instance;
	}
	
	
	private static String $proj = null;
	private static String $webinf = null;
	private static String $classes = null;
	private static String $template = null;
	
	
	/**
	 * 返回classes路径
	 * */
	public String getClassesPath(){
		if($classes == null){
			$classes = this.getClass().getResource("").getPath();
			$classes = $classes.substring(0, $classes.lastIndexOf("/classes")) + "/classes";
		}
		return $classes;
	}
	
	
	/**
	 * 返回WEB-INF路径
	 * */
	public String getWEBINF(){
		if($webinf == null){
			$webinf = this.getClass().getResource("").getPath();
			$webinf = $webinf.substring(0, $webinf.lastIndexOf("/classes"));
		}
		return $webinf;
	}
	
	
	/**
	 * 获得工程目录
	 * */
	public String getProjectPath(){
		if($proj == null){
			$proj = this.getClass().getResource("").getPath();
			$proj = $proj.substring(0, $proj.lastIndexOf("/WEB-INF"));
		}
		return $proj;
	}
	
	
	
	/**
	 * 得到模板文件目录位置
	 * */
	public String getTemplateFolder(){
		if($template == null){
			$template = this.getWEBINF().replace("/", File.separator) + File.separator + "template" + File.separator;
		}
		return $template;
	}
}
